package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.config.TopicConfig;
import com.lkd.contract.SupplyContract;
import com.lkd.emq.Topic;
import com.lkd.service.TaskService;
import com.lkd.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@Topic(TopicConfig.TASK_SUPPLY_TOPIC)
public class TaskAutoCreateSupplyHandler implements MsgHandler {
    @Autowired
    private TaskService taskService;

    @Override
    public void process(String jsonMsg) throws IOException {
        // 反序列化
        SupplyContract contract = JsonUtil.getByJson(jsonMsg, SupplyContract.class);

        // 自动创建补货工单
        taskService.autoCreateSupplyTask(contract);
    }
}
